// 1. 结构体
/**
 * 1. 定义结构体
 * 2. 访问结构成员
 * 3. 结构作为函数参数
 * 4. #41 函数返回结构 static
 * 5. 指向结构的指针（通过指针返回结构成员）
 * 6. typedef关键字使用
 * 
 * 扩展:
 * 1. 
 * 
*/

#include <iostream>
#define __mark 41

/*
 * #41 函数返回结构
*/
#if __mark == 41
#include <string.h>
#include <time.h>
struct Girl
{
  char name[50];
  int age;
  char character[100];
};
struct Girl createGirl(void);
char *randName(void);
int main(void)
{
  struct Girl g1;
  g1 = createGirl();

  std::cout << "女孩姓名 : " << g1.name << "\n"
            << "女孩年龄 : " << g1.age << "\n"
            << "女孩性格 : " << g1.character << std::endl;
  printf("-------------end----------------\n");
  // system("pause");
  return 0;
}

struct Girl createGirl(void)
{
  static struct Girl g;
  const char *character[50] = {"活泼可爱", "古灵精怪", "聪明伶俐", "温柔贤惠", "善解人意"};
  srand((unsigned)time(NULL));
  g.age = rand() % 31 + 8;
  strcpy(g.name, randName());

  int i = 0;
  i = rand() % 5;
  strcpy(g.character, character[i]);
  return g;
}

char *randName(void)
{
  static char name[50];
  int l = rand() % 8 + 3; // 姓名长度 3~11
  for (int i = 0; i < l; i++)
  {
    char c = rand() % 26 + (65 + 32);
    if (0 == i)
    {
      c -= 32;
    }
    name[i] = c;
  }
  name[l] = '\0';
  return name;
}

#elif __mark == 'z'

int main()
{

  printf("-------------end----------------\n");
  // system("pause");
  return 0;
}

#endif